import dayjs from "dayjs"

//生成单位对应的format
export let map = {
    'half_hour': 'day',
    'day': 'month',
    'month': 'year'
}

export const getComparisonName = (chartState, comparison) => {
    let period = chartState.period
    if (comparison === 'last_period') {
        if (period === 'half_hour') {
            return '前天'
        } else if (period === 'day') {
            return '上个月'
        } else if (period === 'month') {
            return '去年'
        }
    } else if (comparison === 'last_year') {
        return '去年同期'
    } else if (comparison === 'custom') {
        return dayjs(chartState.comparisonDate).format(getConfig(map[period]).format)
    } else {
        return ''
    }
}

/**
 * 
 * @param {string} type interval类型
 * @returns {Object} 格式化配置
 */
export function getConfig(type = 'half_hour') {
    const configs = {
        half_hour: {
            label: '昨日',
            format: 'HH:mm'
        },
        day: {
            label: '本月',
            format: 'MM-DD'
        },
        month: {
            label: '今年',
            format: 'YYYY-MM'
        },
        quarter: {
            label: '季度',
            format: 'YYYY第Q季度'
        },
        year: {
            label: '全年',
            format: 'YYYY'
        }
    }
    return configs[type] || configs.half_hour
}